package o;

import android.content.Context;
import android.content.pm.PackageInfo;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import java.io.BufferedInputStream;
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public abstract class dnw {
    public static boolean ˊ(File file) {
        if (file == null || !file.exists()) {
            return true;
        }
        if (file.isFile()) {
            return file.delete();
        }
        File[] listFiles = file.listFiles();
        if (listFiles != null && listFiles.length > 0) {
            for (File ˊ : listFiles) {
                ˊ(ˊ);
            }
        }
        return file.delete();
    }

    public static String ˏ(String str, Context context) {
        PackageInfo ˏ = dnx.ˏ(str, context);
        if (ˏ == null || ˏ.applicationInfo == null || ˏ.applicationInfo.sourceDir == null || "".equals(ˏ.applicationInfo.sourceDir)) {
            return null;
        }
        return ˏ.applicationInfo.sourceDir;
    }

    public static String ˎ(String str, String str2) {
        Closeable fileInputStream;
        Closeable bufferedInputStream;
        Throwable e;
        Throwable th;
        String str3 = null;
        try {
            MessageDigest instance = MessageDigest.getInstance(str2);
            fileInputStream = new FileInputStream(str);
            try {
                bufferedInputStream = new BufferedInputStream(fileInputStream);
            } catch (NoSuchAlgorithmException e2) {
                e = e2;
                bufferedInputStream = null;
                try {
                    Logger.ˋ("FileUtil", "getFileHashData NoSuchAlgorithmException", e);
                    ˎ(bufferedInputStream);
                    ˎ(fileInputStream);
                    return str3;
                } catch (Throwable th2) {
                    th = th2;
                    ˎ(bufferedInputStream);
                    ˎ(fileInputStream);
                    throw th;
                }
            } catch (FileNotFoundException e3) {
                bufferedInputStream = null;
                Logger.e("FileUtil", "getFileHashData FileNotFoundException");
                ˎ(bufferedInputStream);
                ˎ(fileInputStream);
                return str3;
            } catch (IOException e4) {
                e = e4;
                bufferedInputStream = null;
                Logger.ˋ("FileUtil", "getFileHashData IOException", e);
                ˎ(bufferedInputStream);
                ˎ(fileInputStream);
                return str3;
            } catch (IllegalArgumentException e5) {
                e = e5;
                bufferedInputStream = null;
                Logger.ˋ("FileUtil", "getFileHashData IllegalArgumentException", e);
                ˎ(bufferedInputStream);
                ˎ(fileInputStream);
                return str3;
            } catch (IndexOutOfBoundsException e6) {
                e = e6;
                bufferedInputStream = null;
                Logger.ˋ("FileUtil", "getFileHashData IndexOutOfBoundsException", e);
                ˎ(bufferedInputStream);
                ˎ(fileInputStream);
                return str3;
            } catch (Throwable e7) {
                bufferedInputStream = null;
                th = e7;
                ˎ(bufferedInputStream);
                ˎ(fileInputStream);
                throw th;
            }
            try {
                byte[] bArr = new byte[WXMediaMessage.MINI_PROGRAM__THUMB_LENGHT];
                long j = 0;
                while (true) {
                    int read = bufferedInputStream.read(bArr);
                    if (read == -1) {
                        break;
                    }
                    instance.update(bArr, 0, read);
                    j += (long) read;
                }
                if (j > 0) {
                    str3 = doa.ˋ(instance.digest());
                }
                ˎ(bufferedInputStream);
                ˎ(fileInputStream);
            } catch (NoSuchAlgorithmException e8) {
                e7 = e8;
                Logger.ˋ("FileUtil", "getFileHashData NoSuchAlgorithmException", e7);
                ˎ(bufferedInputStream);
                ˎ(fileInputStream);
                return str3;
            } catch (FileNotFoundException e9) {
                Logger.e("FileUtil", "getFileHashData FileNotFoundException");
                ˎ(bufferedInputStream);
                ˎ(fileInputStream);
                return str3;
            } catch (IOException e10) {
                e7 = e10;
                Logger.ˋ("FileUtil", "getFileHashData IOException", e7);
                ˎ(bufferedInputStream);
                ˎ(fileInputStream);
                return str3;
            } catch (IllegalArgumentException e11) {
                e7 = e11;
                Logger.ˋ("FileUtil", "getFileHashData IllegalArgumentException", e7);
                ˎ(bufferedInputStream);
                ˎ(fileInputStream);
                return str3;
            } catch (IndexOutOfBoundsException e12) {
                e7 = e12;
                Logger.ˋ("FileUtil", "getFileHashData IndexOutOfBoundsException", e7);
                ˎ(bufferedInputStream);
                ˎ(fileInputStream);
                return str3;
            }
        } catch (NoSuchAlgorithmException e13) {
            e7 = e13;
            bufferedInputStream = null;
            fileInputStream = null;
            Logger.ˋ("FileUtil", "getFileHashData NoSuchAlgorithmException", e7);
            ˎ(bufferedInputStream);
            ˎ(fileInputStream);
            return str3;
        } catch (FileNotFoundException e14) {
            bufferedInputStream = null;
            fileInputStream = null;
            Logger.e("FileUtil", "getFileHashData FileNotFoundException");
            ˎ(bufferedInputStream);
            ˎ(fileInputStream);
            return str3;
        } catch (IOException e15) {
            e7 = e15;
            bufferedInputStream = null;
            fileInputStream = null;
            Logger.ˋ("FileUtil", "getFileHashData IOException", e7);
            ˎ(bufferedInputStream);
            ˎ(fileInputStream);
            return str3;
        } catch (IllegalArgumentException e16) {
            e7 = e16;
            bufferedInputStream = null;
            fileInputStream = null;
            Logger.ˋ("FileUtil", "getFileHashData IllegalArgumentException", e7);
            ˎ(bufferedInputStream);
            ˎ(fileInputStream);
            return str3;
        } catch (IndexOutOfBoundsException e17) {
            e7 = e17;
            bufferedInputStream = null;
            fileInputStream = null;
            Logger.ˋ("FileUtil", "getFileHashData IndexOutOfBoundsException", e7);
            ˎ(bufferedInputStream);
            ˎ(fileInputStream);
            return str3;
        } catch (Throwable e72) {
            bufferedInputStream = null;
            fileInputStream = null;
            th = e72;
            ˎ(bufferedInputStream);
            ˎ(fileInputStream);
            throw th;
        }
        return str3;
    }

    public static String ˏ(String str) {
        if (str == null) {
            return "";
        }
        int lastIndexOf = str.lastIndexOf(".");
        return lastIndexOf < 0 ? null : str.substring(lastIndexOf + 1, str.length());
    }

    public static void ˎ(Closeable closeable) {
        if (closeable != null) {
            try {
                closeable.close();
            } catch (Throwable e) {
                Logger.ˋ("FileUtil", "Closeable exception", e);
            }
        }
    }

    public static boolean ˋ(String str) {
        if (str != null) {
            return new File(str).exists();
        }
        return false;
    }

    /* JADX WARNING: inconsistent code. */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public static java.io.File ˊ(java.lang.String r6, java.lang.String r7) {
        /*
        r1 = 0;
        r0 = android.text.TextUtils.isEmpty(r6);
        if (r0 != 0) goto L_0x000d;
    L_0x0007:
        r0 = android.text.TextUtils.isEmpty(r7);
        if (r0 == 0) goto L_0x000f;
    L_0x000d:
        r0 = r1;
    L_0x000e:
        return r0;
    L_0x000f:
        r5 = new java.io.File;	 Catch:{ FileNotFoundException -> 0x0040, all -> 0x0055 }
        r5.<init>(r6);	 Catch:{ FileNotFoundException -> 0x0040, all -> 0x0055 }
        r0 = new java.io.File;	 Catch:{ FileNotFoundException -> 0x0040, all -> 0x0055 }
        r0.<init>(r7);	 Catch:{ FileNotFoundException -> 0x0040, all -> 0x0055 }
        r2 = r0.exists();	 Catch:{ FileNotFoundException -> 0x006e, all -> 0x0055 }
        if (r2 == 0) goto L_0x0022;
    L_0x001f:
        ˊ(r0);	 Catch:{ FileNotFoundException -> 0x006e, all -> 0x0055 }
    L_0x0022:
        r4 = new java.io.FileOutputStream;	 Catch:{ FileNotFoundException -> 0x006e, all -> 0x0055 }
        r4.<init>(r0);	 Catch:{ FileNotFoundException -> 0x006e, all -> 0x0055 }
        r3 = new java.io.BufferedOutputStream;	 Catch:{ FileNotFoundException -> 0x0072, all -> 0x0062 }
        r2 = 1048576; // 0x100000 float:1.469368E-39 double:5.180654E-318;
        r3.<init>(r4, r2);	 Catch:{ FileNotFoundException -> 0x0072, all -> 0x0062 }
        r2 = new java.util.zip.ZipOutputStream;	 Catch:{ FileNotFoundException -> 0x0076, all -> 0x0065 }
        r2.<init>(r3);	 Catch:{ FileNotFoundException -> 0x0076, all -> 0x0065 }
        ˏ(r5, r2);	 Catch:{ FileNotFoundException -> 0x007a, all -> 0x0067 }
        ˎ(r2);
        ˎ(r3);
        ˎ(r4);
        goto L_0x000e;
    L_0x0040:
        r0 = move-exception;
        r2 = r1;
        r3 = r1;
        r0 = r1;
    L_0x0044:
        r4 = "FileUtil";
        r5 = "getZipFile, FileNotFoundException";
        o.dna.ˊ(r4, r5);	 Catch:{ all -> 0x006a }
        ˎ(r1);
        ˎ(r2);
        ˎ(r3);
        goto L_0x000e;
    L_0x0055:
        r0 = move-exception;
        r3 = r1;
        r4 = r1;
    L_0x0058:
        ˎ(r1);
        ˎ(r3);
        ˎ(r4);
        throw r0;
    L_0x0062:
        r0 = move-exception;
        r3 = r1;
        goto L_0x0058;
    L_0x0065:
        r0 = move-exception;
        goto L_0x0058;
    L_0x0067:
        r0 = move-exception;
        r1 = r2;
        goto L_0x0058;
    L_0x006a:
        r0 = move-exception;
        r4 = r3;
        r3 = r2;
        goto L_0x0058;
    L_0x006e:
        r2 = move-exception;
        r2 = r1;
        r3 = r1;
        goto L_0x0044;
    L_0x0072:
        r2 = move-exception;
        r2 = r1;
        r3 = r4;
        goto L_0x0044;
    L_0x0076:
        r2 = move-exception;
        r2 = r3;
        r3 = r4;
        goto L_0x0044;
    L_0x007a:
        r1 = move-exception;
        r1 = r2;
        r2 = r3;
        r3 = r4;
        goto L_0x0044;
        */
        throw new UnsupportedOperationException("Method not decompiled: o.dnw.ˊ(java.lang.String, java.lang.String):java.io.File");
    }

    private static void ˏ(File file, ZipOutputStream zipOutputStream) {
        Closeable fileInputStream;
        Closeable bufferedInputStream;
        IOException e;
        Throwable th;
        Exception e2;
        Closeable closeable = null;
        int read;
        if (file.isDirectory()) {
            File[] listFiles = file.listFiles();
            if (listFiles != null) {
                for (File file2 : listFiles) {
                    if (file2.exists() && !file2.getName().endsWith(".zip")) {
                        ˏ(file2, zipOutputStream);
                    }
                }
                return;
            }
            return;
        }
        byte[] bArr = new byte[1048576];
        try {
            fileInputStream = new FileInputStream(file);
            try {
                bufferedInputStream = new BufferedInputStream(fileInputStream, 1048576);
            } catch (IOException e3) {
                e = e3;
                bufferedInputStream = null;
                closeable = fileInputStream;
                try {
                    Logger.ˋ("FileUtil", "zipFile, Exception:" + e.toString());
                    ˎ(bufferedInputStream);
                    ˎ(closeable);
                } catch (Throwable th2) {
                    th = th2;
                    fileInputStream = closeable;
                    ˎ(bufferedInputStream);
                    ˎ(fileInputStream);
                    throw th;
                }
            } catch (Exception e4) {
                e2 = e4;
                bufferedInputStream = null;
                try {
                    Logger.ˋ("FileUtil", "zipFile, Exception:" + e2.toString());
                    ˎ(bufferedInputStream);
                    ˎ(fileInputStream);
                } catch (Throwable th3) {
                    th = th3;
                    ˎ(bufferedInputStream);
                    ˎ(fileInputStream);
                    throw th;
                }
            } catch (Throwable th4) {
                th = th4;
                bufferedInputStream = null;
                ˎ(bufferedInputStream);
                ˎ(fileInputStream);
                throw th;
            }
            try {
                zipOutputStream.putNextEntry(new ZipEntry(file.getName()));
                while (true) {
                    read = bufferedInputStream.read(bArr);
                    if (read != -1) {
                        zipOutputStream.write(bArr, 0, read);
                    } else {
                        zipOutputStream.flush();
                        zipOutputStream.closeEntry();
                        ˎ(bufferedInputStream);
                        ˎ(fileInputStream);
                        return;
                    }
                }
            } catch (IOException e5) {
                e = e5;
                closeable = fileInputStream;
                Logger.ˋ("FileUtil", "zipFile, Exception:" + e.toString());
                ˎ(bufferedInputStream);
                ˎ(closeable);
            } catch (Exception e6) {
                e2 = e6;
                Logger.ˋ("FileUtil", "zipFile, Exception:" + e2.toString());
                ˎ(bufferedInputStream);
                ˎ(fileInputStream);
            }
        } catch (IOException e7) {
            e = e7;
            bufferedInputStream = null;
            Logger.ˋ("FileUtil", "zipFile, Exception:" + e.toString());
            ˎ(bufferedInputStream);
            ˎ(closeable);
        } catch (Exception e8) {
            e2 = e8;
            bufferedInputStream = null;
            fileInputStream = null;
            Logger.ˋ("FileUtil", "zipFile, Exception:" + e2.toString());
            ˎ(bufferedInputStream);
            ˎ(fileInputStream);
        } catch (Throwable th5) {
            th = th5;
            bufferedInputStream = null;
            fileInputStream = null;
            ˎ(bufferedInputStream);
            ˎ(fileInputStream);
            throw th;
        }
    }
}
